

package AddressBook.View.UtilityView;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

/**
 * This Class allows to customize the cells of a Jtable
 */
public class JtableRender extends DefaultTableCellRenderer {

    /**
     * This method returns the default table cell renderer.
     *
     * @param table      The JTable
     * @param value      The value to assign to the cell at [row, column]
     * @param isSelected True if cell is selected
     * @param hasFocus   True if cell has focus
     * @param row        The row of the cell to render
     * @param column     The column of the cell to render
     * @return the default table cell renderer
     */
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        Color clr;

        if (!isSelected) {
            if (row % 2 == 0) {
                clr = Color.LIGHT_GRAY;
            } else clr = Color.WHITE;
            component.setBackground(clr);
        }
        return component;
    }
}
